package sparksql

import org.apache.spark.SparkContext
import org.apache.spark.sql.{DataFrame, SparkSession}

object DataFrame2 {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder().appName(this.getClass.getSimpleName).master("local[*]").getOrCreate()
    //    val sc: SparkContext = spark.sparkContext
    val df: DataFrame = spark
      .read
      .option("header", true)
      .option("inferSchema", true)
      .csv("C:\\Users\\lynn\\Desktop\\name.txt")
    df.createTempView("v_csv")
    spark.sql(
      s"""
         |select * from v_csv where age > 20
         |
         |""".stripMargin
    ).write.json("C:\\Users\\lynn\\Desktop\\name.json")

  }
}
